package com.vr.xuecheng.checkcode.controller;

import com.vr.xuecheng.checkcode.model.CheckCodeParamsDto;
import com.vr.xuecheng.checkcode.model.CheckCodeResultDto;
import com.vr.xuecheng.checkcode.service.CheckCodeService;
import com.vr.xuecheng.checkcode.vo.PhoneCodeVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Mr.M
 * @version 1.0
 * @description 验证码服务接口
 * @date 2022/9/29 18:39
 */
@Tag(name = "验证码服务接口")
@RestController
public class CheckCodeController {

    @Resource(name = "PicCheckCodeService")
    private CheckCodeService picCheckCodeService;


    @Operation(summary = "生成验证信息")
    @PostMapping(value = "/pic")
    public CheckCodeResultDto generatePicCheckCode(CheckCodeParamsDto checkCodeParamsDto) {
        return picCheckCodeService.generate(checkCodeParamsDto);
    }

    @Operation(summary = "校验", parameters = {
            @Parameter(
                    name = "name",
                    description = "业务名称",
                    required = true,
                    schema = @Schema(type = "string"),
                    in = ParameterIn.QUERY
            ),
            @Parameter(
                    name = "key",
                    description = "验证key",
                    required = true,
                    schema = @Schema(type = "string"),
                    in = ParameterIn.QUERY
            ),
            @Parameter(
                    name = "code",
                    description = "验证码",
                    required = true,
                    schema = @Schema(type = "string"),
                    in = ParameterIn.QUERY
            )
    })
    @PostMapping(value = "/verify")
    public Boolean verify(@RequestParam("key") String key, @RequestParam("code") String code) {
        Boolean isSuccess = picCheckCodeService.verify(key, code);
        return isSuccess;
    }
    @Operation(summary = "生成手机验证码")
    @PostMapping(value = "/phone")
    public PhoneCodeVO generatePhoneCode(@RequestParam("param1") String cellphone) {
        return picCheckCodeService.generatePhoneCode(cellphone);
    }
}
